package com.app.ui.activity.base;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.viewbinding.ViewBinding;

import com.app.ui.activity.R;

import com.library.baseui.activity.BaseApplication;
import com.library.baseui.activity.BaseCompatActivity;
import com.library.baseui.utile.other.StatusBarUtile;
import com.library.baseui.utile.toast.ToastUtile;
import com.retrofits.net.common.RequestBack;

/**
 * Created by Administrator on 2016/9/7.
 */
public class RootActivity<T extends ViewBinding> extends BaseCompatActivity implements RequestBack {
    private BaseApplication baseApplication;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseApplication = (BaseApplication) getApplication();
        setContentView();
        onInitView();
    }

    protected void onInitView() {
    }

    protected T bidingView;

    protected void setContentView() {
        bidingView = getLayoutBinding(getLayoutInflater());
        if (bidingView != null) {
            setContentView(bidingView.getRoot());
        }
    }

    protected T getLayoutBinding(LayoutInflater inflater) {
        return null;
    }

    @Override
    protected void setImmersion() {
        super.setImmersion();
        if (bidingView != null) {
            View view = findViewById(R.id.status_bar_height_view);
            if (view != null) {
                ViewGroup.LayoutParams lp = view.getLayoutParams();
                lp.height = StatusBarUtile.getStatusBarHeight(this);
            }
        }
    }

    //=======================等待dialog===============================
    // private DialogCustomWaiting dialog;

    protected void dialogShow() {
        /*if (dialog == null) {
            dialog = new DialogCustomWaiting(this);
        }
        dialog.show();*/
    }

    protected void dialogDismiss() {
        /*if (dialog == null) {
            return;
        }
        dialog.dismiss();*/
    }


    //=============================网络请求回调==========================================
    @Override
    public void onBack(int what, Object obj, String msg, String other) {
        showToast(msg, other);
    }

    @Override
    public void onBackProgress(int i, String s, String s1, long l, long l1) {

    }

    private void showToast(String msg, String other) {
        if (!TextUtils.isEmpty(other)) {
            ToastUtile.showToast(other);
            return;
        }
        if (!TextUtils.isEmpty(msg)) {
            ToastUtile.showToast(msg);
            return;
        }
    }
}
